<?
//<meta http-equiv="content-type" content="text/html; charset=utf-8">
include "head.php";

if ( $_REQUEST["table_prefix"] ) $table_prefix = $_REQUEST["table_prefix"];
?>
<p><a href="index.php">HOME</a> / <strong>Concept Viewer</strong></p>
<p><strong><?=$query_cui?></strong></p>
<?
$query = "select sab, def from MRDEF where cui = '$query_cui' order by sab"; 
$result = mysql_query($query) or die("\n<br>Query:$query\n<br>Error:".mysql_error());
if ( mysql_num_rows($result) ) {
	echo "\n<p>Definition</p><ol>";
	while( $row = mysql_fetch_array($result) ) {
		echo "\n<li>{$row['sab']} / {$row['def']}</li>";
	}
	echo "\n</ol>";
}

$query = "select tui, sty from MRSTY where cui = '$query_cui' order by sty"; 
$result = mysql_query($query) or die("\n<br>Query:$query\n<br>Error:".mysql_error());
if ( mysql_num_rows($result) ) {
	echo "\n<p>Semantic Type</p><ol>";
	while( $row = mysql_fetch_array($result) ) {
		echo "\n<li>{$row['tui']} / {$row['sty']}</li>";
	}
	echo "\n</ol>";
}

$query = "select sab, str from MRCONSO where cui = '$query_cui' order by sab"; 
$result = mysql_query($query) or die("\n<br>Query:$query\n<br>Error:".mysql_error());
if ( mysql_num_rows($result) ) {
	echo "\n<p>String</p><ol>";
	while( $row = mysql_fetch_array($result) ) {
		echo "\n<li>{$row['sab']} / {$row['str']}</li>";
	}
	echo "\n</ol>";
}

$query = "select a.rel, a.cui2, b.str, b.sab_list from MRREL a join {$table_prefix}concept b on (a.cui2 = b.cui) where a.cui1 = '$query_cui' order by a.rel, b.str";
$result = mysql_query($query) or die("\n<br>Query:$query\n<br>Error:".mysql_error());
if ( mysql_num_rows($result) ) {
	echo "\n<p>Relation</p><ol>";
	while( $row = mysql_fetch_array($result) ) {
		echo "\n<li>{$row['rel']} 
				/ {$row['cui2']} 
				/ {$row['str']} 
				/ {$row['sab_list']} <a href='concept_viewer_cui.php?query_cui={$row['cui2']}'>&raquo;</a> 
				</li>";
	}
	echo "\n</ol>";
}

$query = "select fstr from {$table_prefix}concept_tree where cui = '$query_cui'"; 
$result = mysql_query($query) or die("\n<br>Query:$query\n<br>Error:".mysql_error());
if ( mysql_num_rows($result) ) {
	echo "\n<p>Concept tree</p><ol>";
	while( $row = mysql_fetch_array($result) ) {
		$fstr = str_replace("_", " / ", $row['fstr']);
		echo "\n<li>{$fstr}</li>";
	}
	echo "\n</ol>";
}
?>
<p>&nbsp;</p>
<?
include "tail.php";
?>